/*
 * Copyright (c) 2022.版权所有高金磊
 */

package 领扣算法.力扣计划.算法基础.搜索旋转排序数组;

public class Main {
    public static void main(String arg[]){//main--来自高金磊

        new Main().search(new int[]{4,5,6,7,0,1,2},0);
    }

    public int search(int[] nums, int target) {
        //二分查找改进
        int res=find(nums,target,0,nums.length-1);
        return res;
    }

    private int find(int[] nums, int target, int left, int right) {
        if (left>right){
            return -1;
        }

       int middle=left+(right-left)/2;
       if (nums[middle]!=target){
           int a=find(nums,target,left,middle-1);
           if (a!=-1)
               return a;
           int b=find(nums, target, middle+1, right);
           if (b!=-1)
               return b;
       }else {
           return middle;
       }
       return -1;

    }
}
